using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using net_work.Data.Entity.System;
using net_work.Data.Enum.System;

namespace net_work.Config.DataBaseConfig.System;

/// <summary>
/// 文件使用实体配置类
/// </summary>
public class FileUseEntityTypeConfiguration : IEntityTypeConfiguration<FileUse>
{
    public void Configure(EntityTypeBuilder<FileUse> builder)
    {
        builder.ToTable("sys_file_use");

        builder.HasKey(fu => fu.Id);

        // 配置字段名映射
        builder.Property(fu => fu.Id).HasColumnName("file_use_id");
        builder.Property(fu => fu.BusinessCode).HasColumnName("file_bns_code").IsRequired().HasMaxLength(64)
            .HasConversion(bns => bns.ToString(), bns => (BusinessType)Enum.Parse(typeof(BusinessType), bns));
        builder.Property(fu => fu.BusinessId).HasColumnName("file_bns_id").IsRequired();

        builder.Property(fu => fu.CreatedBy).HasColumnName("create_by").IsRequired().HasMaxLength(64);
        builder.Property(fu => fu.CreatedTime).HasColumnName("create_time").IsRequired();
        builder.Property(fu => fu.UpdatedBy).HasColumnName("update_by").IsRequired().HasMaxLength(64);
        builder.Property(fu => fu.UpdatedTime).HasColumnName("update_time").IsRequired();
        builder.Property(fu => fu.Remark).HasColumnName("remark").HasMaxLength(256);
        builder.Property(fu => fu.DelFlag).HasColumnName("del_flag").HasDefaultValue('0');
    }
}